home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / cli / mx2src.arc / LOGIN.MOD < prev    next >
Text File  |  1989-01-05  |  5KB  |  141 lines

  1. IMPLEMENTATION MODULE  LOGIN;
  2. FROM    Terminal   IMPORT  ReadString,WriteString,WriteLn;
  3. FROM    TermBase   IMPORT  DoWrite,WriteProc;
  4. FROM    Strings    IMPORT  String,Compare,CompareResults,Pos,Copy,Concat,
  5.                            Length;
  6. FROM    GEMDOS     IMPORT  OldTerm,SetPath,GetPath,Exec,ExecMode,SetDrv;
  7. IMPORT  TextIO;
  8. FROM    Streams    IMPORT  StreamKinds,CloseStream;
  9. FROM    SYSTEM     IMPORT  ADR;
  10. CONST   USERS = 16;
  11.         SEED1 = 3844364602;
  12.         SEED2 = 1561798242;
  13. TYPE    sarray  =       ARRAY [0..7] OF CHAR;
  14. VAR     user,password,prg       :       ARRAY [0..USERS-1] OF String;
  15.         path,com                :       ARRAY [0..USERS-1] OF String;
  16.         input                   :       String;
  17.         black,gulampath         :       String;
  18.         clipath                 :       String;
  19.         i,j,index,spos,epos     :       CARDINAL;
  20.         userfound,ok            :       BOOLEAN;
  21.         normal,noecho           :       WriteProc;
  22.         result                  :       INTEGER;
  23.         drvmap                  :       LONGCARD;
  24.  
  25. PROCEDURE       NoEcho(char: CHAR);
  26. BEGIN
  27. END             NoEcho;
  28.  
  29. PROCEDURE       login;
  30. BEGIN
  31.         TextIO.SetDefaultIO("PASSWD",READ,result);
  32.         normal:=DoWrite;
  33.         noecho:=NoEcho;
  34.         FOR i:=0 TO USERS-1 DO               (* read in userfile *)
  35.                 TextIO.ReadString(input);
  36.                 spos:=0;
  37.                 ok:=Pos(input,":",spos,epos);
  38.                 Copy(input,spos,epos-spos,user[i]);
  39.                 spos:=epos+1;
  40.                 ok:=Pos(input,":",spos,epos);
  41.                 Copy(input,spos,epos-spos,password[i]);
  42.                 spos:=epos+1;
  43.                 ok:=Pos(input,":",spos,epos);
  44.                 Copy(input,spos,epos-spos,path[i]);
  45.                 spos:=epos+1;
  46.                 ok:=Pos(input,":",spos,epos);
  47.                 Copy(input,spos,epos-spos,prg[i]);
  48.                 spos:=epos+1;
  49.                 Copy(input,spos,Length(input)-spos,com[i]);
  50.         END; (* for *)
  51.         CloseStream(TextIO.in,result);
  52.         CloseStream(TextIO.out,result);
  53.         input[0]:=33c; input[1]:='e'; input[2]:=0c;
  54.         WriteString(input);
  55.         LOOP
  56.            REPEAT
  57.               userfound:=FALSE;
  58.               WriteLn;
  59.               WriteString("Login: ");
  60.               ReadString(input);
  61.               WriteLn;
  62.            UNTIL input[0]#0c;
  63.            FOR i:=0 TO USERS-1 DO
  64.                IF Compare(input,user[i])=Equal THEN
  65.                   userfound:=TRUE;
  66.                   index:=i;
  67.                END;
  68.            END;
  69.            IF (password[index][0]#0c) OR (NOT userfound) THEN
  70.            WriteString("Password: ");
  71.            DoWrite:=noecho;
  72.            ReadString(input);
  73.            DoWrite:=normal;
  74.            WriteLn;
  75.            black:=user[index];
  76.            crypt(input,black);
  77.            IF (Compare(black,password[index])=Equal) AND userfound THEN
  78.               EXIT;
  79.            END;
  80.            END;
  81.            IF (password[index][0]=0c) AND userfound THEN EXIT END;
  82.            WriteLn;
  83.            WriteString("Login incorrect");
  84.         END; (* loop *)
  85.         GetPath(gulampath,0);
  86.         IF path[index][0]=0c THEN
  87.            GetPath(clipath,0);
  88.         ELSE
  89.            clipath:=path[index];
  90.            IF clipath[0]#'\' THEN
  91.               IF ORD(clipath[0])>60H THEN
  92.                  SetDrv(ORD(clipath[0])-61H,drvmap);
  93.               ELSE
  94.                  SetDrv(ORD(clipath[0])-41H,drvmap);
  95.               END;
  96.               j:=1;
  97.               REPEAT
  98.                 clipath[j-1]:=clipath[j];
  99.                 INC(j);
  100.               UNTIL (clipath[j-1]=0c);
  101.            END;
  102.         END;
  103.         IF NOT ((clipath[0]='\') AND (clipath[1]=0c)) THEN
  104.            Concat(clipath,"\",clipath);
  105.         END;
  106.         IF prg[index][0]=0c THEN
  107.            prg[index]:=gulampath;
  108.         IF NOT ((prg[index][0]='\') AND (prg[index][1]=0c)) THEN
  109.            Concat(prg[index],"\",prg[index]);
  110.         END;
  111.            Concat(prg[index],"gulam.prg",prg[index]);
  112.         END;
  113.         ok:=SetPath(clipath);
  114.         input[0]:=33c; input[1]:='f'; input[2]:=0c;
  115.         WriteString(input);
  116.         Exec(loadExecute,prg[index],"","",result);
  117. END     login;
  118.  
  119. PROCEDURE       crypt(VAR red,crypto: ARRAY OF CHAR);
  120. VAR     seed            :       ARRAY [0..1] OF LONGCARD;
  121.         chptr           :       POINTER TO sarray;
  122.         black           :       CHAR;
  123. BEGIN
  124.         seed[0]:=SEED1;
  125.         seed[1]:=SEED2;
  126.         chptr:=ADR(seed);
  127.         FOR i:=0 TO 7 DO
  128.             FOR j:=0 TO 7 DO
  129.                 chptr^[i]:=CHAR(BITSET(chptr^[i])/BITSET(red[j]));
  130.                 chptr^[i]:=CHAR(BITSET(chptr^[i])/BITSET(crypto[j]));
  131.             END;
  132.             black:=CHAR(40H+CARDINAL( BITSET(chptr^[i]) * BITSET(31) ));
  133.             crypto[i]:=black;
  134.         END;
  135.         crypto[8]:=0c;
  136. END             crypt;
  137.  
  138. BEGIN
  139. END     LOGIN.
  140.  
  141.